﻿using System.Runtime.Serialization;
using System;

namespace LuxDiner.Model.Orders
{
    [DataContract]
    public class VProductOrderDetailsModel:MBase
    {
        [Model]
        [DataMember]
        public string OrderNo { get; set; }
        [Model]
        [DataMember]
        public System.DateTime NoteDate { get; set; }
        [Model]
        [DataMember]
        public int HouseID { get; set; }
        [Model]
        [DataMember]
        public int OperatorUserID { get; set; }
        [Model]
        [DataMember]
        public decimal TotalMoney { get; set; }
        [Model]
        [DataMember]
        public int Method { get; set; }
        [Model]
        [DataMember]
        public int ID { get; set; }
        [Model]
        [DataMember]
        public int ProductID { get; set; }
        [Model]
        [DataMember]
        public decimal Quantity { get; set; }
        [Model]
        [DataMember]
        public decimal CostMoney { get; set; }
        [Model]
        [DataMember]
        public string Retention { get; set; }
        [Model]
        [DataMember]
        public string ProductNo { get; set; }
        [Model]
        [DataMember]
        public string ProductName { get; set; }
        [Model]
        [DataMember]
        public string UnitName { get; set; }
        [Model]
        [DataMember]
        public string AssistantUnitName { get; set; }
        [Model]
        [DataMember]
        public Nullable<int> AssistantUnitRate { get; set; }
        [Model]
        [DataMember]
        public string AssociatedDealNo { get; set; }
        [Model]
        [DataMember]
        public Nullable<int> CustomerID { get; set; }
        [Model]
        [DataMember]
        public string Corporation { get; set; }
        [Model]
        [DataMember]
        public string RealName { get; set; }
        [Model]
        [DataMember]
        public string Address { get; set; }
        [Model]
        [DataMember]
        public string Mobile { get; set; }
        [Model]
        [DataMember]
        public Nullable<int> CType { get; set; }
        [Model]
        [DataMember]
        public string CustomerNo { get; set; }

        #region Help
        [DataMember]
        public string AssistantQuantity
        {
            get
            {
                if (AssistantUnitRate != null && AssistantUnitRate > 0 && !string.IsNullOrEmpty(AssistantUnitName))
                {
                    var d = (int)Quantity / AssistantUnitRate;
                    var m = (int)Quantity % AssistantUnitRate;
                    if (d > 0)
                    {
                        var ret = string.Format("{0}{1}", d, AssistantUnitName);
                        if (m > 0)
                            ret += string.Format("{0}{1}", m, UnitName);
                        return ret;
                    }
                }
                return "";
            }
        }
        [DataMember]
        public string CustomerComplexName
        {
            get
            {
                if (!string.IsNullOrEmpty(AssociatedDealNo))
                    return string.Format("{0}【{1}】 {2}", Corporation, RealName, Mobile);
                else
                    return null;
            }
        }
        #endregion
    }

    [DataContract]
    public class VProductOrderDetailsCollection : ModelCollectionBase<VProductOrderDetailsModel> { }
}
